package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.archive.letax.IdentityType;
import com.tengju.user.domain.model.archive.sign.Sign;
import com.tengju.user.domain.model.archive.sign.SignId;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.DateUtil;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.SignDO;

public class SignConvert {

    public static Sign convert(SignDO signDo) {
        if (signDo == null){
            return null;
        }
        return new Sign(
                new SignId(signDo.getId()),
                new UserIdCode(signDo.getIdCode()),
                IdentityType.fromVal(signDo.getBeforeIdentity()),
                IdentityType.fromVal(signDo.getCurrentIdentity()),
                IdentityType.fromVal(signDo.getHistoryIdentity()),
                signDo.getIsSigned(),
                signDo.getIsView(),
                DateUtil.dateToLocalDateTime(signDo.getSignTime()),
                signDo.getNoticeStatus());
    }

    public static SignDO convert(Sign sign) {
        if (sign == null){
            return null;
        }
        SignDO signDO = new SignDO();
        signDO.setIdCode(sign.getIdCode().getValue());
        signDO.setBeforeIdentity(sign.getBeforeIdentity().getVal());
        signDO.setCurrentIdentity(sign.getCurrentIdentity().getVal());
        signDO.setHistoryIdentity(sign.getHistoryIdentity() == null ? null : sign.getHistoryIdentity().getVal());
        signDO.setIsSigned(sign.getIsSigned());
        signDO.setIsView(sign.getIsView());
        signDO.setSignTime(DateUtil.localDateTimeToDate(sign.getSignTime()));
        signDO.setNoticeStatus(sign.getNoticeStatus());
        return signDO;
    }

    public static SignDO convert(SignId signId, Sign sign) {
        SignDO signDO = convert(sign);
        signDO.setId(signId.getValue());
        return signDO;
    }
}
